import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import sites.aeg.AegSite;
import sites.aeg.tags.DetailPageAegTag;
import sites.electrozine.ElectrozineSite;
import sites.electrozine.tags.ProductInfoEzTag;
import core.HtmlServices;
import core.ISiteMapper;

public class MainTest {

    private void aegtest() throws IOException {
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("script.sql")));

        AegSite aeg = new AegSite();

        for (String s : aeg.getAllUrls()) {
            System.out.println("Read url: " + s);
            ISiteMapper dtg = new DetailPageAegTag();
            String filename = aeg.saveUrlToDisk(s);
            System.out.println("Parse file: " + filename);
            aeg.parsePage(new File(filename), dtg);
            dtg.generateScript(out);
        }
        // aeg.saveUrlToDisk("http://www.aeg.be/nl-BE/Products/Koeling/Inbouw/Koelkasten/SKD71800F0");
        // ISiteMapper dtg = new DetailPageTag();
        // aeg.parsePage(new File("Koeling-Inbouw-Koelkasten-SKD71800F0"), dtg);

        out.flush();
        out.close();

    }

    private void eztest() throws IOException {
        ProductInfoEzTag pi = new ProductInfoEzTag();
        ElectrozineSite es = new ElectrozineSite();

        // es.parsePage(new File("proddetails-17890.xml"), pi);
        // System.out.println(pi.getProductDescr());
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("script.sql")));
        pi.generateScript(out);
        // es.readAllFromDisk(pi, out);
        es.saveAllFromSite(true, pi, out);

        out.flush();
        out.close();

    }

    private String escapeChars(String str) {
        if (str == null) return "";
        return str.replaceAll("'", "\\\\'");
    }

    public static void main(String[] args) throws IOException {
        MainTest m = new MainTest();
        m.eztest();


    }
}
